import os
import simsym
import symtypes
import errno
import model
import signal
import ptypes
import ProcessQueue
import Lock
import HardwareRegisters

class ProcessDescr(simsym.tstruct(
		prio	= ptypes.PRIO,
		status	= ptypes.PROCSTATUS,
		regs	= HardwareRegisters.GENREGSET,
		statwd	= ptypes.STATUSWD,
		ip	= simsym.SInt,
		stack	= ptypes.PSTACK,
		data	= ptypes.PDATA,
		code	= ptypes.PCODE,
		mem	= ptypes.MEMDESC,
		memsize	= simsym.SInt
		)):
	def _declare_assumptions(self, assume):
		super(ProcessDescr, self)._declare_assumptions(assume)
	
	@model.methodwrap(
		pr	= ptypes.PRIO,
		stat	= ptypes.PROCSTATUS,
		pstack	= ptypes.PSTACK,
		pdata	= ptypes.PDATA,
		pcode	= ptypes.PCODE,
		mem	= ptypes.MEMDESC,
		msz	= simsym.SInt)
	def INIT(self, pr, stat, pstack, pdata, pcode, mem, msz):
		self.prio	= pr
		self.status	= stat
		#self.waitingtype	= none
		#self.kind	= knd
		self.regs.INIT
		self.statwd	= 0
		self.ip		= 0
		self.data	= pdata
		self.code	= pcode
		self.stack	= pstack
		self.mem	= mem
		self.memsize	= msz

	@model.methodwrap()
	def Priority(self):
		return self.prio

	@model.methodwrap(pr = ptypes.PRIO)
	def SetPriority(self, pr):
		self.prio = pr
	
	@model.methodwrap()
	def ProcessStatus(self):
		return self.status

	@model.methodwrap()
	def SetProcessStatusToNew(self):
		self.status = ptypes.pstnew

	@model.methodwrap()
	def SetProcessStatusToTerminated(self):
		self.status = ptypes.pstterm

	@model.methodwrap()
	def SetProcessStatusToReady(self):
		self.status = ptypes.pstready

	@model.methodwrap()
	def SetProcessStatusToRunning(self):
		self.status = ptypes.pstrunning

	@model.methodwrap()
	def SetProcessStatusToWaiting(self):
		self.status = ptypes.pstwaiting

	@model.methodwrap()
	def StoreSize(self):
		return self.memsize

	@model.methodwrap()
	def StoreDescr(self):
		return self.mem

	@model.methodwrap(newmem = ptypes.MEMDESC)
	def SetStoreDescr(self, newmem):
		self.mem = newmem
		self.memsize = ptypes.hole_size(newmem)

	@model.methodwrap(
		pregs	= HardwareRegisters.GENREGSET,
		pstatwd	= ptypes.STATUSWD,
		pip	= simsym.SInt,
		pstack	= ptypes.PSTACK)
	def SetFullContext(self, pregs, pip, pstatwd, pstack):
		self.regs	= pregs
		self.ip		= pip
		self.statwd	= pstatwd
		self.stack	= pstack
		pass

model_class = ProcessDescr
